/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"3E94D74D-98C8-48D7-A89C-68264522CB16"}
 */
function onDataChange_codigo(oldValue, newValue, event) {
	if (controller.getSelectedIndex() == 1 && globals.gEstadoAbm == 1)
	{
		elements.descripcion.requestFocus()
		return true
	}
	else
	{
		elements.descripcion.requestFocus()
		codigo = oldValue
		return true
	}
}

/**
 * @properties={typeid:24,uuid:"C2639698-2C71-49E2-9C24-267F51C50DA0"}
 */
function validar() {
	controller.setSelectedIndex(1)
	if (globals.gEstadoAbm == 1)
	{
		var $sql = 'SELECT rubro_id FROM subcapitulo WHERE empresa = ? AND capitulo = ? AND codigo = ?'
		var $args = [empresa, capitulo, codigo]
		var $ds = databaseManager.getDataSetByQuery('contable',$sql,$args,-1)
		if ($ds.getMaxRowIndex() != 0) 
		{		
			return [false,false,"El código ingresado ya existe"]
		}
	}
	return [true]
}

/**
 * @properties={typeid:24,uuid:"366372FC-46B4-448A-9505-CAE5E4465031"}
 */
function imprimir()
{
	//forms.subcapitulo_impresion.controller.showPrintPreview()
	jasper('impresion')
}

/**
 * @properties={typeid:24,uuid:"7B7B6F09-3830-4829-817D-93836AFD2A98"}
 */
function pdf()
{
	//globals.metodoPdf('subcapitulo_impresion','Subcapitulos - ' + globals.glegajo,true)
	jasper('pdf')
}

/**
 * @properties={typeid:24,uuid:"1BC0F53C-F5FE-4A74-838A-1D2F874D976F"}
 */
function xls()
{
	jasper('xls')
}

/**
 * @properties={typeid:24,uuid:"10D70029-1AE7-452C-B5C3-0521829B493E"}
 */
function csv()
{
	jasper('csv')
}

/**
 * @param {String} tipo
 *
 * @properties={typeid:24,uuid:"F4288386-504B-4BC6-9DA9-F08C8CB6B5FD"}
 */
function jasper(tipo)
{
	var $params = {
		userv: usuarios_to_uservs.razon_social
	}
	
	globals.metodoJasper(tipo,'contable/subcapitulos.jasper','Subcapitulos',foundset,$params)
}